import json


def get_str_format_keys(s: str) -> list:
    """
    获取字符串中包含的变量  如“1{a}3”
    :param s:
    :return:
    """
    def format_key(fs: str):
        try:
            fs = fs.format(**d)
            return [d]
        except KeyError as e:
            key = str(e)[1:-1]
            d[key] = ''
            format_key(fs)
    d = {}
    format_key(s)
    return list(d.keys())


def clean_dict_none(d: dict) -> dict:
    data = {}
    for k, v in d.items():
        if v:
            data[k] = v
    return data


if __name__ == '__main__':
    s = get_str_format_keys('q{哈}fq')
    print(s)





